<template>
  <div class="box">
    <el-input
      v-model="input"
      placeholder="输入账号"
      clearable
      style="margin-bottom: 0.125rem"
    />
    <el-input
      v-model="password"
      type="密码"
      placeholder="输入密码"
      show-password
    />
    <el-button color="#626aef" style="margin-top: 0.125rem" @click="logins"
      >登录</el-button
    >
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { useRouter } from "vue-router";
import { login } from "../axios/http";
import { usemd5 } from "../hooks/index";
import { useStore } from "vuex";
const store = useStore();
const input = ref("");
const password = ref();
const router = useRouter();
interface User {
  id: number;
  name: string;
  permissions: string;
  passwrod?: string;
}
const tableData = ref<User>({
  id: 1,
  name: "",
  permissions: "",
  passwrod: "",
});
async function logins() {
  console.log(password.value);
  let arr = await login(input.value, usemd5(password.value));
  console.log(arr);
  tableData.value = arr.data[0];
  store.commit("management", tableData.value);
  if (arr.data.length) {
    router.push("/page");
  }
}
</script>
<style scoped lang="scss">
.box {
  width: 5rem;
  margin: 0.25rem;
}
</style>
